//
//  CHViews.m
//  CHSelectedAnswers
//
//  Created by Summer on 15/12/22.
//  Copyright © 2015年 Summer. All rights reserved.
//

// 屏幕_宽_高
#define SCREEN_WIDTH  ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT  ([[UIScreen mainScreen] bounds].size.height)

#define IPHONE6_W 375.0f
#define IPHONE6_H 667.0f

// 控件缩放比例
#define SCALE_WIDTH(w) (SCREEN_WIDTH/375.0*w)

// 如果是iPhone4
#define RECTFIX_WIDTH(a) (IS_IPHONE4 ? a : SCALE_WIDTH(a))
#define RECTFIX_HEIGHT(a) (IS_IPHONE4 ? a : SCALE_HEIGHT(a))

// 左右两边的间距
#define MARGIN_1 10.0f

// 男女之间的间距
#define MARGIN_2 5.0f

// 第一个按钮的宽
#define BUTTON_1_W 95.0f

// 按钮的高
#define BUTTON_H 30.0f

// 按钮的Y值
#define BUTTON_Y  18.0f


#import "CHViews.h"

@interface CHViews()
@property(nonatomic,strong)UIButton  *button1;
@property(nonatomic,strong)UIButton  *button2;
@property(nonatomic,strong)UIButton  *button3;
@property(nonatomic,strong)UIButton  *button4;
@end

@implementation CHViews

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initControl];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initControl];
    }
    return self;
}

/** 初始化控件 **/
-(void) initControl{
    
    self.button1 = [self addButton];
    self.button2 = [self addButton];
    self.button3 = [self addButton];
    self.button4 = [self addButton];}

/** 快捷创建 **/
-(UIButton *)addButton{
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundColor:[UIColor redColor]];
    [self addSubview:button];
    
    
   button.titleLabel.font = [UIFont  boldSystemFontOfSize:15];


    return button;
}


-(void)initwithTextLabel:(NSString*)textLabel1 withTextLabel:(NSString*)textLabel2 withTextLabel:(NSString*)textLabel3 withTextLabel:(NSString*)textLabel4{

   
    [self.button1  setTitle:textLabel1 forState:UIControlStateNormal];
    [self.button2  setTitle:textLabel2 forState:UIControlStateNormal];
    
    [self.button3  setTitle:textLabel3 forState:UIControlStateNormal];
    [self.button4  setTitle:textLabel4 forState:UIControlStateNormal];
   




}





- (void)layoutSubviews{
    [super layoutSubviews];
    [self setControlFrame];
}



/** 设置子控件位置 **/
-(void)setControlFrame{
    
    
    //button1
    CGFloat btn1W = SCALE_WIDTH(BUTTON_1_W);
    CGFloat btn1H = SCALE_WIDTH(BUTTON_H);
    CGFloat btn1X = MARGIN_1;
    CGFloat btn1Y = BUTTON_Y;
    
    self.button1.frame = CGRectMake(btn1X, btn1Y, btn1W, btn1H);
    
    
    
    
    //button2
    
    CGFloat w = (SCREEN_WIDTH - (MARGIN_1 * 2) - (MARGIN_2 * 3) - btn1W) / 3;
    
    CGFloat btn2W = w;
    CGFloat btn2H = btn1H;
    CGFloat btn2X = CGRectGetMaxX(self.button1.frame) + MARGIN_2;
    CGFloat btn2Y = BUTTON_Y;
    
    self.button2.frame = CGRectMake(btn2X, btn2Y, btn2W, btn2H);
    
    
    
    
    //button3
    
    CGFloat btn3W = w;
    CGFloat btn3H = btn1H;
    CGFloat btn3X = CGRectGetMaxX(self.button2.frame) + MARGIN_2;
    CGFloat btn3Y = BUTTON_Y;
    
    self.button3.frame = CGRectMake(btn3X, btn3Y, btn3W, btn3H);
    
    
    
    
    //button4
    CGFloat btn4W = w;
    CGFloat btn4H = btn1H;
    CGFloat btn4X = CGRectGetMaxX(self.button3.frame) + MARGIN_2;
    CGFloat btn4Y = BUTTON_Y;
    
    self.button4.frame = CGRectMake(btn4X, btn4Y, btn4W, btn4H);
}



@end
